/**
	Pulsar engine. Core.
	Virtual translation disk

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

namespace pl
{

class DriveTranslate : Drive
{
public:
	explicit DriveTranslate(const pl::Filepath& rootPath, const pl::String<4>& prefix);
	virtual ~DriveTranslate()
	{
	}

	virtual bool isAccepted(const pl::Filepath& fileName) const;

	virtual bool handleTrasnlation(pl::Filepath& fileName);

	virtual pl::FileError getTotalDiskSpace(pl_uint64 &nBytes) const
	{
		if (_pDrive != NULL)
		{
			return _pDrive->getTotalDiskSpace(nBytes);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError getFreeDiskSpace(pl_uint64 &nBytes) const
	{
		if (_pDrive != NULL)
		{
			return _pDrive->getFreeDiskSpace(nBytes);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError renameFile(const pl::Filepath& oldName, const pl::Filepath& newName)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->renameFile(oldName, newName);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError deleteFile(const pl::Filepath& fileName)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->deleteFile(fileName);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError makeDir(const pl::Filepath& dirName)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->makeDir(dirName);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError deleteDir(const pl::Filepath& dirName)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->deleteDir(dirName);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError checkFileExist(const pl::Filepath& fileName)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->checkFileExist(fileName);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError getFileAttrib(const pl::Filepath& fileName, pl_uint32& attrib)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->getFileAttrib(fileName, attrib);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError setFileAttrib(const pl::Filepath& fileName, pl_uint32 attrib)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->setFileAttrib(fileName, attrib);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError getFileSize(const pl::Filepath& fileName, pl_int64& size)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->getFileSize(fileName, size);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError setFileSize(const pl::Filepath& fileName, pl_int64 size)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->setFileSize(fileName, size);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError getFileDate(const pl::Filepath& fileName, pl::FileDateType type, pl::DateTime& date)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->getFileDate(fileName, type, date);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FileError setFileDate(const pl::Filepath& fileName, pl::FileDateType type, const pl::DateTime& date)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->setFileDate(fileName, type, date);
		}
		return pl::FILE_ERROR_DRIVE_NOT_FOUND;
	}

	virtual pl::FindFile* findFile(const pl::Filepath& mask)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->findFile(mask);
		}
		return NULL;
	}

	virtual StreamRead* openFileRead(const pl::Filepath& fileName, pl_uint32 shareAndAttrib)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->openFileRead(fileName, shareAndAttrib);
		}
		return NULL;
	}

	virtual StreamWrite* openFileWrite(const pl::Filepath& fileName, pl_uint32 shareAndAttrib)
	{
		if (_pDrive != NULL)
		{
			return _pDrive->openFileWrite(fileName, shareAndAttrib);
		}
		return NULL;
	}

private:
	Drive* _pDrive;
	pl::String<4> _prefix;
	pl::Filepath _root;
};

} // namespace pl

//
// End of file 'pulsar_translate_disk.h'
//
